home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libs / kpathsea / basename.c < prev    next >
C/C++ Source or Header  |  1995-06-25  |  1KB  |  52 lines

  1. /* basename.c: return the last element in a path.
  2.  
  3. Copyright (C) 1992, 94, 95 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  */
  18.  
  19. /* Have to include this first to get c-auto.h.  */
  20. #include <kpathsea/config.h>
  21.  
  22. #ifndef HAVE_BASENAME /* rest of file */
  23.  
  24. #include <kpathsea/c-pathch.h>
  25.  
  26. /* Return NAME with any leading path stripped off.  This returns a
  27.    pointer into NAME.  For example, `basename ("/foo/bar.baz")'
  28.    returns "bar.baz".  */
  29.  
  30. const_string
  31. basename P1C(const_string, name)
  32. {
  33.   const_string base = NULL;
  34.   unsigned len = strlen (name);
  35.   
  36.   for (len = strlen (name); len > 0; len--)
  37.     {
  38.       if (IS_DIR_SEP (name[len - 1]))
  39.         {
  40.           base = name + len;
  41.           break;
  42.         }
  43.     }
  44.  
  45.   if (!base)
  46.     base = name;
  47.   
  48.   return base;
  49. }
  50.  
  51. #endif /* not HAVE_BASENAME */
  52.